Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log user creation timestamp #3416

Merged
merged 12 commits into from
Jun 20, 2024
Merged

Conversation

sjanssen2
Copy link
Contributor

Addressing #3378 this PR will use SQL's NOW() function to log creation of a new user account (validated or not). This is handy for:
a) reconstructing user growth
b) pruning accounts that have been created but not validated for X days

I've also added this information to the user's profile page, if the value is not None:
image

@coveralls
Copy link

Coverage Status

coverage: 92.873% (+0.002%) from 92.871%
when pulling ca55a2f on jlab:log_user_creation_timestamp
into 9de3f38 on qiita-spots:dev.

Copy link
Member

@antgonza antgonza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sjanssen2, this is great; really appreciate the contribution.

@@ -1891,7 +1891,8 @@ CREATE TABLE qiita.qiita_user (
receive_processing_job_emails boolean DEFAULT false,
social_orcid character varying DEFAULT NULL,
social_researchgate character varying DEFAULT NULL,
social_googlescholar character varying DEFAULT NULL
social_googlescholar character varying DEFAULT NULL,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few requests:

  1. Could you undo the changes on this file and add them as a SQL patch? Do not worry about changing the DBSchema, I'll do that with this and other minor changes it has happened before the release. As a reminder, the reason those changes were made in this file was because I merged all changes into a single file a few PRs ago.
  2. Could you make the default of creation_timestamp NOW()? That way it will be controlled by the database during creation.

Thank you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@1 oh, I thought the patching mechanism is dead as I didn't see patch files anymore :-) I've moved the change into 93.sql. Changes are much cleaner this way.
@2 love to :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. in fact, I think you should use 92.sql which is the patch for this release; fine to do that on the other PR if you want me to merge this one first
  2. 👍🏽

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@1: I moved the alterations to 92.sql. I didn't know that you collect changes for a release. However, tests fail. I might overlook something, but I have the impression that no patch is currently applied in the github actions?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2. Could you make the default of creation_timestamp NOW()? That way it will be controlled by the database during creation.

As a follow up: I've just made the DB changes in my "productive" instance and found that all existing users (which did not have the creation_timestamp column of cause) now have the timestamp of DB change as their creation_timestamp information, even though they existed for many month in the past.

Is that really the behaviour we want to see in a productive Qiita, @antgonza ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's fine.

qiita_db/user.py Outdated
Comment on lines 236 to 243

# log timestamp of user creation
sql = """UPDATE qiita.{0}
SET creation_timestamp = NOW()
WHERE email = %s""".format(cls._table)
qdb.sql_connection.perform_as_transaction(sql, [email])

# Add system messages to user
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the default in the database is now(), then this is not required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like removing this code a lot :-) I was not sure how SQL will deal with old entries that have None in this column.

@@ -75,7 +75,8 @@ def setUp(self):
'receive_processing_job_emails': True,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue with this test and my suggestion about using now() in the database is that there is going to be a small difference on the tests so they will need to be adjusted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to account for these unpredictable time differences with your "before < obs < after" assertions, e.g. here https://github.com/jlab/qiita/blob/1488be79e9468e240ea318ae8920fd6559030307/qiita_db/test/test_user.py#L170-L198

@@ -50,7 +50,7 @@ INSERT INTO qiita.user_level VALUES (7, 'wet-lab admin', 'Can access the private
-- Data for Name: qiita_user; Type: TABLE DATA; Schema: qiita; Owner: antoniog
--

INSERT INTO qiita.qiita_user VALUES ('[email protected]', 4, '$2a$12$gnUi8Qg.0tvW243v889BhOBhWLIHyIJjjgaG6dxuRJkUM8nXG9Efe', 'Dude', 'Nowhere University', '123 fake st, Apt 0, Faketown, CO 80302', '111-222-3344', NULL, NULL, NULL, false, '0000-0002-0975-9019', 'Rob-Knight', '_e3QL94AAAAJ');
INSERT INTO qiita.qiita_user VALUES ('[email protected]', 4, '$2a$12$gnUi8Qg.0tvW243v889BhOBhWLIHyIJjjgaG6dxuRJkUM8nXG9Efe', 'Dude', 'Nowhere University', '123 fake st, Apt 0, Faketown, CO 80302', '111-222-3344', NULL, NULL, NULL, false, '0000-0002-0975-9019', 'Rob-Knight', '_e3QL94AAAAJ', '2015-12-03 13:52:42.751331-07');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the failure, you need to remove this change too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, I thought that the new patches should be free of test data. I've moved this addition of the creation_timestamp info into the 92.sql patch. Let's wait for the tests.

@sjanssen2 sjanssen2 requested a review from antgonza June 20, 2024 10:54
Copy link
Member

@antgonza antgonza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you.

@antgonza antgonza merged commit 8b3f717 into qiita-spots:dev Jun 20, 2024
4 checks passed
@coveralls
Copy link

Coverage Status

coverage: 92.818% (+0.002%) from 92.816%
when pulling 6601e24 on jlab:log_user_creation_timestamp
into cca6de7 on qiita-spots:dev.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants